<template>
  <div>
    <el-card>
      <div class="ding">
        试卷名称:<el-input v-model="input" placeholder="请输入内容" clearable @input="search" @clear="clear" />
      </div>
      <el-table
        :data="testtable"
        style="width: 100%"
      >
        <el-table-column
          label="序号"
          type="index"
          width="130px"
        />
        <el-table-column
          label="试卷名称"
          prop="sjname"
        />
        <el-table-column
          label="上传者"
          prop="name"
        >
        </el-table-column>
        <el-table-column
          label="试卷总分"
          prop="tscore"
        />
        <el-table-column
          label="添加时间"
        >
          <template slot-scope="scope">
            {{ scope.row.createtime|moment("YYYY-MM-DD HH:mm:ss") }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200px">
          <template slot-scope="scope">
            <el-button @click="kao(scope.row)"><a class="blue">进行考试</a></el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        :page-sizes="[5, 10, 15, 20]"
        :page-size="5"
        layout="total, sizes, prev, pager, next, jumper"
        :total="t"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>

    <el-dialog
      title="请填写考试信息"
      :visible.sync="dialogVisible"
      width="30%">
      <el-form :model="form">
        <el-form-item label="姓名" >
          <el-input v-model="form.name" autocomplete="off" class="inp"></el-input>
        </el-form-item>
        <el-form-item label="班级" >
          <el-input v-model="form.classbj" autocomplete="off" class="inp"></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="form.phone" autocomplete="off" class="inp"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="startkao">开始考试</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      testtable: [],
      size: 5,
      page: 1,
      t: 0,
      pageisornot: false,
      uploader: '',
      input: '',
      dialogVisible:false,
      testid:'',
      form:{
        name:'',
        classbj:'',
        phone:''
      }
    }
  },
  computed: {},
  watch: {},
  created() {
    this.gettest()
    // this.uploader=sessionStorage.getItem("user")
  },
  mounted() {},
  methods: {
    async gettest() {
      this.pageisornot = false
      var res = await this.http.get('/test/test/', {
        params: {
          page: this.page,
          size: this.size
        }
      })
      console.log(res)
      if (res.data.code == 200) {
        this.testtable = res.data.data
        this.t = res.data.total
      }
    },
    add() {
      this.$router.push('/kaotiadd')
    },
    async search() {
      if (!this.pageisornot) {
        this.page = 1
      }
      if (this.input != '') {
        var res = await this.http.get('/test/test/', {
          params: { sjname: this.input, page: this.page,
            size: this.size }
        })
        if (res.data.code == 200) {
          this.testtable = res.data.data
        }
      } else {
        this.gettest()
      }
      this.pageisornot = true
    },
    clear() {
      this.gettest()
    },
    handleSizeChange(v) {
      this.size = v
      if (this.pageisornot) {
        this.search()
      } else {
        this.gettest()
      }
    },
    handleCurrentChange(v) {
      this.page = v
      if (this.pageisornot) {
        this.search()
      } else {
        this.gettest()
      }
    },
    kao(row) {
      this.testid=row.id
      this.dialogVisible=true
      
    },
    startkao(){
      // sessionStorage.setItem('info',this.form)
      this.$router.push({ path: '/kao', query: { id: this.testid ,info:this.form}})
    }
  }
}
</script>
<style scoped>
    .el-input{
        width: 200px;
        margin-left: 7px;
    }
    .el-pagination{
      margin-top: 20px;
      text-align: center;
    }
    .ding .el-button{
        float: right;
    }
    .el-table .el-button{
      background: 0;
      padding-left: 0;
      padding-right: 0;
      display: inline-block;
      border:0;
    }
    .blue{
      color: #3175fb;
    }
    /* .el-dialog .el-button{
      margin: 0 auto;
    } */
    .inp{
      width: 300px;
    }
</style>
